package me.wangqu.weiyouqu.web.rest.business.dao.impl;

import me.wangqu.weiyouqu.web.rest.business.dao.AboutDao;
import me.wangqu.weiyouqu.web.rest.business.model.BaseModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by joln on 2016/8/2.
 */
@Repository
public class AboutImpl implements AboutDao {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    @Override
    public List<BaseModel> getAboutData() {
        StringBuffer sql = new StringBuffer(128);
        sql.append("select name,link from about ");
        return jdbcTemplate.query(sql.toString(), new RowMapper<BaseModel>() {

            @Override
            public BaseModel mapRow(ResultSet rs, int rowNum) throws SQLException {
                BaseModel bases = new BaseModel();
                bases.setTitle(rs.getString("name"));
                bases.setUrl(rs.getString("link"));
                return bases;
            }
        });
    }
}
